```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑距离 - 动态规划详解</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .code-block pre {
            margin: 0;
            padding: 1rem;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        .highlight {
            background: linear-gradient(90deg, rgba(56, 182, 255, 0.1) 0%, rgba(56, 182, 255, 0) 100%);
            border-left: 4px solid #38b6ff;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .table-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
            gap: 0;
        }
        .table-cell {
            padding: 0.75rem;
            border: 1px solid #e2e8f0;
            text-align: center;
            font-size: 0.875rem;
        }
        .table-header {
            background-color: #f1f5f9;
            font-weight: 600;
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row items-center justify-between">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">编辑距离</h1>
                    <h2 class="text-2xl md:text-3xl font-medium mb-6">动态规划经典问题解析</h2>
                    <p class="text-lg opacity-90 leading-relaxed">
                        探索如何高效计算两个字符串之间的最小编辑操作数，深入理解动态规划的核心思想与应用场景。
                    </p>
                    <div class="mt-8 flex space-x-4">
                        <a href="#problem" class="px-6 py-3 bg-white text-indigo-600 rounded-lg font-medium shadow-md hover:bg-opacity-90 transition duration-300">
                            <i class="fas fa-book mr-2"></i>问题解析
                        </a>
                        <a href="#solution" class="px-6 py-3 bg-indigo-900 bg-opacity-30 rounded-lg font-medium hover:bg-opacity-40 transition duration-300">
                            <i class="fas fa-lightbulb mr-2"></i>解决方案
                        </a>
                    </div>
                </div>
                <div class="md:w-2/5">
                    <div class="bg-white bg-opacity-10 rounded-2xl p-6 backdrop-blur-sm border border-white border-opacity-20">
                        <div class="flex items-center mb-4">
                            <div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
                            <div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                        </div>
                        <div class="code-block">
                            <pre><code class="text-sm" id="hero-code">// 示例输入
word1 = "horse", word2 = "ros"

// 最少操作步骤:
1. horse → rorse (替换 'h' 为 'r')
2. rorse → rose (删除 'r')
3. rose → ros (删除 'e')

// 最终结果: 3</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-16">
        <!-- Problem Section -->
        <section id="problem" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-question text-indigo-600"></i>
                </div>
                <h3 class="text-2xl font-bold text-gray-800">问题描述</h3>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8">
                <div class="p-6 md:p-8">
                    <div class="prose max-w-none">
                        <p class="text-lg leading-relaxed mb-6">
                            给定两个单词 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word1</span> 和 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word2</span>，计算出将 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word1</span> 转换成 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word2</span> 所使用的最少操作数。
                        </p>
                        <p class="leading-relaxed mb-6">
                            你可以对一个单词进行如下三种操作：
                        </p>
                        <ul class="space-y-3 mb-6">
                            <li class="flex items-start">
                                <span class="inline-flex items-center justify-center w-6 h-6 rounded-full bg-indigo-100 text-indigo-600 mr-3 flex-shrink-0">
                                    <i class="fas fa-plus text-xs"></i>
                                </span>
                                <span>插入一个字符</span>
                            </li>
                            <li class="flex items-start">
                                <span class="inline-flex items-center justify-center w-6 h-6 rounded-full bg-purple-100 text-purple-600 mr-3 flex-shrink-0">
                                    <i class="fas fa-minus text-xs"></i>
                                </span>
                                <span>删除一个字符</span>
                            </li>
                            <li class="flex items-start">
                                <span class="inline-flex items-center justify-center w-6 h-6 rounded-full bg-pink-100 text-pink-600 mr-3 flex-shrink-0">
                                    <i class="fas fa-exchange-alt text-xs"></i>
                                </span>
                                <span>替换一个字符</span>
                            </li>
                        </ul>
                        <div class="highlight p-6 rounded-lg mb-6">
                            <h4 class="font-bold text-lg mb-3 text-indigo-600 flex items-center">
                                <i class="fas fa-lightbulb mr-2"></i>示例
                            </h4>
                            <p class="font-mono mb-2">word1 = "horse", word2 = "ros"</p>
                            <p class="mb-1">最少 3 步操作：</p>
                            <ol class="list-decimal pl-5 space-y-1">
                                <li>horse → rorse (将 'h' 替换为 'r')</li>
                                <li>rorse → rose (删除 'r')</li>
                                <li>rose → ros (删除 'e')</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Solution Section -->
        <section id="solution">
            <div class="flex items-center mb-8">
                <div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-code text-indigo-600"></i>
                </div>
                <h3 class="text-2xl font-bold text-gray-800">解决方案</h3>
            </div>

            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <!-- Algorithm Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-4">
                                <i class="fas fa-project-diagram text-blue-500"></i>
                            </div>
                            <h4 class="text-xl font-bold">核心算法</h4>
                        </div>
                        <p class="text-gray-600 mb-4">
                            使用<strong>动态规划</strong>来解决这个问题，构建一个二维数组来存储子问题的解。
                        </p>
                        <ul class="space-y-2 text-sm">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>定义 dp[i][j] 为 word1 前 i 个字符转换到 word2 前 j 个字符所需的最少操作数</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>若字符相同，则继承左上角的值</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>若字符不同，则取左、上、左上三个方向的最小值加1</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Complexity Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-50 flex items-center justify-center mr-4">
                                <i class="fas fa-stopwatch text-purple-500"></i>
                            </div>
                            <h4 class="text-xl font-bold">复杂度分析</h4>
                        </div>
                        <div class="space-y-4">
                            <div>
                                <p class="font-medium text-gray-700 mb-1">时间复杂度</p>
                                <p class="text-sm text-gray-600">O(m×n)</p>
                                <div class="w-full bg-gray-200 rounded-full h-2 mt-1">
                                    <div class="bg-purple-500 h-2 rounded-full" style="width: 85%"></div>
                                </div>
                            </div>
                            <div>
                                <p class="font-medium text-gray-700 mb-1">空间复杂度</p>
                                <p class="text-sm text-gray-600">O(m×n)</p>
                                <div class="w-full bg-gray-200 rounded-full h-2 mt-1">
                                    <div class="bg-blue-500 h-2 rounded-full" style="width: 85%"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Visualization Card -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-pink-50 flex items-center justify-center mr-4">
                                <i class="fas fa-chart-line text-pink-500"></i>
                            </div>
                            <h4 class="text-xl font-bold">可视化演示</h4>
                        </div>
                        <p class="text-gray-600 mb-4">
                            下方是一个动态规划表格的可视化示例，展示了从 "horse" 到 "ros" 的转换过程。
                        </p>
                        <a href="#dp-table" class="inline-flex items-center text-indigo-600 hover:text-indigo-800 transition duration-300">
                            查看表格 <i class="fas fa-arrow-down ml-1"></i>
                        </a>
                    </div>
                </div>
            </div>

            <!-- DP Explanation -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12">
                <div class="p-6 md:p-8">
                    <h4 class="text-xl font-bold mb-6 flex items-center">
                        <i class="fas fa-sitemap mr-3 text-indigo-500"></i>
                        动态规划思路详解
                    </h4>
                    
                    <div class="prose max-w-none mb-8">
                        <p class="mb-4">
                            动态规划的核心思想是将原问题分解为若干子问题，通过解决子问题来解决原问题，并存储子问题的解以避免重复计算。
                        </p>
                        
                        <h5 class="font-bold text-lg mb-3">1. 定义状态</h5>
                        <p class="mb-4">
                            定义 <span class="font-mono bg-gray-100 px-2 py-1 rounded">dp[i][j]</span> 为将 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word1</span> 的前 <span class="font-mono bg-gray-100 px-2 py-1 rounded">i</span> 个字符转换为 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word2</span> 的前 <span class="font-mono bg-gray-100 px-2 py-1 rounded">j</span> 个字符所需的最少操作数。
                        </p>
                        
                        <h5 class="font-bold text-lg mb-3">2. 初始状态</h5>
                        <p class="mb-4">
                            当其中一个字符串为空时，转换所需的操作数就是另一个字符串的长度：
                        </p>
                        <ul class="list-disc pl-5 space-y-2 mb-4">
                            <li><span class="font-mono bg-gray-100 px-2 py-1 rounded">dp[i][0] = i</span> (删除i个字符)</li>
                            <li><span class="font-mono bg-gray-100 px-2 py-1 rounded">dp[0][j] = j</span> (插入j个字符)</li>
                        </ul>
                        
                        <h5 class="font-bold text-lg mb-3">3. 状态转移方程</h5>
                        <p class="mb-2">
                            对于每个字符对 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word1[i-1]</span> 和 <span class="font-mono bg-gray-100 px-2 py-1 rounded">word2[j-1]</span>：
                        </p>
                        <ul class="list-disc pl-5 space-y-2 mb-4">
                            <li>如果字符相同：<span class="font-mono bg-gray-100 px-2 py-1 rounded">dp[i][j] = dp[i-1][j-1]</span></li>
                            <li>如果字符不同：<span class="font-mono bg-gray-100 px-2 py-1 rounded">dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1</span>
                                <ul class="list-circle pl-5 mt-2 space-y-1">
                                    <li><span class="font-mono bg-gray-100 px-1 py-0.5 rounded">dp[i-1][j]</span>：删除操作</li>
                                    <li><span class="font-mono bg-gray-100 px-1 py-0.5 rounded">dp[i][j-1]</span>：插入操作</li>
                                    <li><span class="font-mono bg-gray-100 px-1 py-0.5 rounded">dp[i-1][j-1]</span>：替换操作</li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="mermaid mb-8">
                        graph TD
                            A[开始] --> B{单词比较}
                            B -->|字符相同| C[dp[i][j] = dp[i-1][j-1]]
                            B -->|字符不同| D[取最小值操作]
                            D --> E[删除: dp[i-1][j]+1]
                            D --> F[插入: dp[i][j-1]+1]
                            D --> G[替换: dp[i-1][j-1]+1]
                            C --> H[继续处理下一个字符]
                            E --> H
                            F --> H
                            G --> H
                            H --> I{是否处理完所有字符?}
                            I -->|否| B
                            I -->|是| J[返回dp[m][n]]
                    </div>
                </div>
            </div>

            <!-- DP Table Visualization -->
            <div id="dp-table" class="mb-12">
                <h4 class="text-xl font-bold mb-6 flex items-center">
                    <i class="fas fa-table mr-3 text-indigo-500"></i>
                    DP 表格可视化 (horse → ros)
                </h4>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="overflow-x-auto">
                            <div class="table-grid mb-4">
                                <div class="table-cell table-header"></div>
                                <div class="table-cell table-header">0</div>
                                <div class="table-cell table-header">r</div>
                                <div class="table-cell table-header">o</div>
                                <div class="table-cell table-header">s</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">0</div>
                                <div class="table-cell bg-green-50 font-bold">0</div>
                                <div class="table-cell bg-green-50">1</div>
                                <div class="table-cell bg-green-50">2</div>
                                <div class="table-cell bg-green-50">3</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">h</div>
                                <div class="table-cell bg-green-50">1</div>
                                <div class="table-cell bg-yellow-100 font-bold">1</div>
                                <div class="table-cell">2</div>
                                <div class="table-cell">3</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">o</div>
                                <div class="table-cell bg-green-50">2</div>
                                <div class="table-cell">2</div>
                                <div class="table-cell bg-blue-100 font-bold">1</div>
                                <div class="table-cell">2</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">r</div>
                                <div class="table-cell bg-green-50">3</div>
                                <div class="table-cell bg-blue-100">2</div>
                                <div class="table-cell">2</div>
                                <div class="table-cell bg-yellow-100">2</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">s</div>
                                <div class="table-cell bg-green-50">4</div>
                                <div class="table-cell">3</div>
                                <div class="table-cell">3</div>
                                <div class="table-cell bg-blue-100 font-bold">2</div>
                            </div>
                            <div class="table-grid">
                                <div class="table-cell table-header">e</div>
                                <div class="table-cell bg-green-50">5</div>
                                <div class="table-cell">4</div>
                                <div class="table-cell">4</div>
                                <div class="table-cell bg-pink-100 font-bold">3</div>
                            </div>
                        </div>
                        
                        <div class="mt-8 grid md:grid-cols-3 gap-6">
                            <div class="p-4 bg-indigo-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <span class="w-5 h-5 rounded-full bg-yellow-100 flex items-center justify-center mr-2">
                                        <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                    </span>
                                    <span class="font-medium">替换操作</span>
                                </div>
                                <p class="text-sm text-gray-600">h→r: 将'h'替换为'r'</p>
                            </div>
                            <div class="p-4 bg-indigo-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <span class="w-5 h-5 rounded-full bg-blue-100 flex items-center justify-center mr-2">
                                        <span class="w-3 h-3 rounded-full bg-blue-500"></span>
                                    </span>
                                    <span class="font-medium">相同字符</span>
                                </div>
                                <p class="text-sm text-gray-600">o与o匹配，继承左上角值</p>
                            </div>
                            <div class="p-4 bg-indigo-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <span class="w-5 h-5 rounded-full bg-pink-100 flex items-center justify-center mr-2">
                                        <span class="w-3 h-3 rounded-full bg-pink-500"></span>
                                    </span>
                                    <span class="font-medium">最终结果</span>
                                </div>
                                <p class="text-sm text-gray-600">最少需要3步操作</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Code Implementation -->
            <div class="mb-12">
                <h4 class="text-xl font-bold mb-6 flex items-center">
                    <i class="fas fa-code-branch mr-3 text-indigo-500"></i>
                    代码实现
                </h4>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="code-block">
                        <pre><code class="text-sm">public int minDistance(String word1, String word2) {
    // 获取两个单词的长度
    int m = word1.length();
    int n = word2.length();
    
    // 创建动态规划数组，dp[i][j]表示word1前i个字符转换到word2前j个字符的最少操作数
    int[][] dp = new int[m + 1][n + 1];
    
    // 初始化边界情况：word1前i个字符转换为空字符串需要删除i个字符
    for (int i = 0; i <= m; i++) {
        dp[i][0] = i;
    }
    
    // 初始化边界情况：空字符串转换为word2前j个字符需要插入j个字符
    for (int j = 0; j <= n; j++) {
        dp[0][j] = j;
    }
    
    // 填充dp数组
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            // 如果当前字符相同，不需要操作
            if (word1.charAt(i - 1) == word2.charAt(j - 1)) {
                dp[i][j] = dp[i - 1][j - 1];
            } else {
                // 取三种操作中最小的操作数：删除、插入、替换
                dp[i][j] = Math.min(Math.min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1;
            }
        }
    }
    
    // 返回将word1转换为word2的最少操作数
    return dp[m][n];
}</code></pre>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis',
            }
        });
        
        // 微交互效果
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```